package com.pucheng.bracelet.app.database.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy.REPLACE
import androidx.room.Query
import androidx.room.Update
import com.pucheng.bracelet.data.bean.AllHertRateBean
import kotlinx.coroutines.flow.Flow

@Dao
interface AllDataHRDao {

    @Insert(onConflict = REPLACE)
    suspend fun insert(vararg bean: AllHertRateBean)

    @Insert(onConflict = REPLACE)
    suspend fun insertToList(list: List<AllHertRateBean>)

    @Update
    suspend fun update(vararg bean: AllHertRateBean)

    @Query("SELECT * FROM hert_rate2")
    fun getAll(): Flow<List<AllHertRateBean>>

    @Query("SELECT * FROM hert_rate2 where date>=datetime('now','start of day','-7 day','weekday 1') AND date<datetime('now','start of day','+0 day','weekday 1')")
    fun getWeekData(): Flow<List<AllHertRateBean>>

    @Query("SELECT * FROM hert_rate2 order by date desc limit 0,7")
    fun get7Days(): Flow<List<AllHertRateBean>>

    @Query("SELECT * FROM hert_rate2 WHERE date = :date")
    fun getDataToDate(date:String): LiveData<AllHertRateBean>

}